;var module = angular.module('CtrlsContent');
module.controller('DiantiselectCtrl',['$scope','$state','api_other','common_service','yamiinfo_service',function($scope,$state,api_other,common_service,yamiinfo_service){
	$scope.list = [];
	$scope.total = 0;
	$scope.title = localStorage.bls_catname;
	$scope.goumaiIdArrays = [];
	$scope.data = {};
	$scope.event = {
		get:function(){
			var obj = {
				userId:localStorage.bls_userId,
				catId:localStorage.catId,
				type:1,
			};
			var promise = api_other.diantiList(obj);
			promise.success(function(data){
				if(data.returnCode == 0){
					$scope.list = data.returnData;
					
				}
			});
		},
		totalCount:function(){
			$scope.total = 0;
			$scope.goumaiIdArrays = [];
			$scope.goumaiArrays = [];
			for (var i = $scope.list.length - 1; i >= 0; i--) {
				if($scope.list[i].checked){
					$scope.total = $scope.total+Number($scope.list[i].price);
					$scope.goumaiIdArrays.push($scope.list[i].id);	
					$scope.goumaiArrays.push($scope.list[i]);	
				}
			}
		},
		submit:function(){
			if($scope.goumaiIdArrays.length>0){
	           var myPopup = common_service.pop1($scope);
	           myPopup.then(function(res) {
	             yamiinfo_service.Model = res;
	             yamiinfo_service.Model.yamiArray = $scope.goumaiArrays;
	             yamiinfo_service.Model.total = $scope.total;
	             $state.go('diantibuy');
	           });
			}
		}
	};
	$scope.event.get();
}])